<?php
namespace  v1;

class Score extends \ResourceClass{
    public $isActive = true;
    public $remark = '积分排行';

    public function get(array $req, array $post, &$result)
    {
        try {
            $order = '';
            //判断type为0还是1  0总分  1 周
            if ($req['type'] == \Orm\UserAccount\UserAccountClass::SCORE_TYPE_TOTAL){
                $order = 'a.score DESC, a.insert_time ASC';
            }elseif($req['type'] == \Orm\UserAccount\UserAccountClass::SCORE_TYPE_WEEK){
                $get_week_type = \Orm\UserAccount\UserAccountClass::get_week($req['week_type']);
                $order = ' a.'.$get_week_type.' DESC , a.insert_time ASC';
            }
            $type = $req['type'];
            $offset = isset($req['offset']) ? $req['offset']: 0;
            $size = isset($req['size']) ? $req['size']: 5;
            $user_account_model = new \Orm\UserAccount\UserAccountModel();
            $user_account_list = $user_account_model->getUserAccountRank($offset,$size,$type,$order,$req['week_type']);
            $result = $user_account_list;
        }catch (\Exception $e) {
            $result['total'] = 0;
            $result['list'] = array();
        }
    }
}